package com.lambda.hybrid.handler;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;

import com.lambda.hybrid.Callback;

import org.json.JSONObject;

public class MakePhoneCallHandler extends AbstractHandler {
    private final Context mContext;

    public MakePhoneCallHandler(Context context) {
        mContext = context;
    }

    @Override
    public void onHandle(String data, Callback callback) throws Exception {
        if (mContext == null) return;

        JSONObject table = new JSONObject(data);
        if (table.has("phoneNumber")) {
            final String phoneNumber = table.getString("phoneNumber");
            Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + phoneNumber));
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            mContext.startActivity(intent);
        }
    }
}
